package com.shens.blog.ui;

import java.awt.*;

import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;

public class MainUi {
    JFrame mainFrame = null;
    MJPanel panel = null;

    public MainUi() {
        this.initFrame();
    }

    private void initFrame() {
        this.mainFrame = new JFrame("flush blog");
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(this.addExitMenu());
        this.mainFrame.setJMenuBar(menuBar);
        this.panel = new MJPanel();
        this.mainFrame.add(this.panel);
    }

    private JMenu addExitMenu() {
        JMenu exitMenu = new JMenu("退出(E)");
        exitMenu.setMnemonic('E');
        exitMenu.addMenuListener(new MenuListener() {
            public void menuSelected(MenuEvent e) {
                System.exit(0);
            }

            public void menuDeselected(MenuEvent e) {
            }

            public void menuCanceled(MenuEvent e) {
            }
        });
        return exitMenu;
    }

    public void appentOutPrint(String string) {
        this.panel.appentOutPrint(string);
    }

    public void show() {
        if (this.mainFrame != null) {
            this.mainFrame.setSize(850, 600);
            this.mainFrame.setResizable(false);
            this.mainFrame.setLocationRelativeTo((Component)null);
            this.mainFrame.setDefaultCloseOperation(3);
            ImageIcon icon = new ImageIcon("./imgs/1.jpg");
            this.mainFrame.setIconImage(icon.getImage());
            this.mainFrame.setVisible(true);
        }

        this.initListener();
    }

    private void initListener() {
        this.panel.addListener();
    }
}
